package com.huluobo.module_travel_policy.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.huluobo.appbase.network.HttpErrorDeal
import com.huluobo.module_travel_policy.repo.TravelPolicyRepo
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

class TravelPolicyViewModel : ViewModel() {
    fun queryTravelPolicy(fromCityId: String, toCityId: String) = flow {
        val data = TravelPolicyRepo().queryTravelPolicy(fromCityId, toCityId)
        emit(data)
    }.catch {
        if (it is Exception) {
            HttpErrorDeal.delHttpError(it)
        }
        emit(null)
    }.asLiveData()
}